package edu.mercer.sse.errors;

import java.util.logging.LogManager;
import java.util.logging.Logger;

import com.google.common.base.Optional;

/**
 * CustomLogger.<p>
 * 
 * Supplies entering, exiting methods using custom logger.<p>
 * 
 * <i>Do not use for <u>custom</u> logger creation. Instead:</i><ul> 
 * 
 * <li><code>LogCustom.obtainLog(String logName)</code>
 * <li><code>LogCustom.obtainLog(String logName, Level logLvl)</code></ul>
 */

final public class CustomLogger extends Logger
{
	public CustomLogger(final String loggerName, final String resourceBundle)
	{
		super(loggerName, resourceBundle);
		
	}//constructor
	

	public CustomLogger(final String loggerName)
	{
		super(loggerName, null);
		
	}//constructor

	
	@Override
	public void entering(final String classNameIn, final String methodNameIn)
	{
		super.finer("Start : " + classNameIn + " : " + methodNameIn);
		
	}//method

		
	@Override
	public void exiting(final String classNameIn, final String methodNameIn)
	{
		super.finer("Fini : " + classNameIn + " : " + methodNameIn);
		
	}//method

	
	/**
	 * Creates or retrieves default Logger.<p>
	 * 
	 * <i>Do not use for <u>custom</u> logger creation. Instead:</i><ul> 
	 * 
	 * <li><code>LogCustom.obtainLog(String logName)</code>
	 * <li><code>LogCustom.obtainLog(String logName, Level logLvl)</code></ul>
	 */
	
	public static CustomLogger getLogger(final String logName)
	{
		final LogManager logMgr = LogManager.getLogManager();
		
		final Optional<Logger> loggerWanted = Optional.fromNullable(logMgr
				.getLogger(logName));
		
		if( loggerWanted.isPresent() )
		{ 
			return (CustomLogger) loggerWanted.get();
			
		}//if
		
		logMgr.addLogger(new CustomLogger(logName, null));

		return (CustomLogger) logMgr.getLogger(logName);
			
	}//method
	
}//class